# _*_ coding:utf-8 _*_
# 开发人员：zhu
# 项目名称：cuttxt
# 开发时间：2022/2/2313:09
# 开发工具：PyCharm
import os

def cutalltxt():
    CUR_PATH = r'D:/filecut/'

    def del_file(path):
        ls = os.listdir(path)
        for i in ls:
            c_path = os.path.join(path, i)
            if os.path.isdir(c_path):
                del_file(c_path)
            else:
                os.remove(c_path)

    del_file(CUR_PATH)
    def getname():
        filenames = []
        for root, dirs, files in os.walk('D:\\ssetest'):
            for file in files:
                fn = os.path.join(root, file)
                filenames.append(fn)
        return filenames
    def cuttxt(fileo):

        with open('%s'%fileo, "r",encoding='UTF-8') as f:
            lines = f.readlines()
        for index, line in enumerate(lines, 1):
            print (index, line)
            with open('D:\\filecut\\%d_%d.txt'%(idx,index), 'w+',encoding='UTF-8') as tmp:
                tmp.write(line)
    filenames=getname()
    for idx, val in enumerate(filenames):
        cuttxt(val)